//
//  ZH_MineWalletViewController.m
//  WisdomStar
//
//  Created by zhangliwen on 2018/10/23.
//  Copyright © 2018年 zhangliwen. All rights reserved.
//

#import "ZH_MineWalletViewController.h"
#import "ZH_WalletTableViewCell.h"
#import "ZH_MineMoneyRecordViewController.h"
#import "ZH_MineWithdrawalViewController.h"
#import "ZH_MineAccoutViewController.h"
@interface ZH_MineWalletViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,weak)UIView *backView;
@property (nonatomic,weak)UIImageView *bgView;
@property (nonatomic,weak)UILabel *moneyLabel;
@property (nonatomic,weak)UILabel *yuLabel;
@property (nonatomic,weak)UITableView *tableView;
@property (nonatomic,weak)UIView *bottomView;
@property (nonatomic,weak)UIButton *leftButton;
@property (nonatomic,weak)UIButton *rightButton;
@property (nonatomic,weak)UILabel *accoutLabel;
@property (nonatomic,weak)UILabel *contentLabel;
@property (nonatomic,weak)UIButton *centerButton;
@property (nonatomic,weak)UIImageView *bottomImage;
@property (nonatomic,weak)UILabel *bottomLabel;
@property (nonatomic,weak)UIButton *bottomButton;
@end

@implementation ZH_MineWalletViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initUserInterface];
}

- (void)initUserInterface{
    self.navigationItem.title = @"我的钱包";
    self.view.backgroundColor = kCommonBackgroudColor;
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"资金记录" style:UIBarButtonItemStylePlain target:self action:@selector(money)];
    [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.view);
        make.height.mas_equalTo(FITSCALE(125));
    }];
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(FITSCALE(90));
        make.left.right.equalTo(self.view);
    }];
    [self.moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(FITSCALE(30));
        make.centerX.equalTo(self.view);
    }];
    [self.yuLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.moneyLabel.mas_bottom).offset(FITSCALE(15));
        make.centerX.equalTo(self.view);
    }];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bgView).offset(FITSCALE(22));
        make.bottom.equalTo(self.bgView).offset(FITSCALE(-27));
        make.left.equalTo(self.view).offset(FITSCALE(22));
        make.right.equalTo(self.view).offset(FITSCALE(-22));
    }];
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bgView.mas_bottom).offset(FITSCALE(19));
        make.left.equalTo(self.view).offset(FITSCALE(11));
        make.right.equalTo(self.view).offset(FITSCALE(-11));
        make.bottom.equalTo(self.view);
    }];
    [self.leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self.bottomView);
        make.right.equalTo(self.bottomView.mas_centerX);
        make.height.mas_equalTo(FITSCALE(40));
    }];
    [self.rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.top.equalTo(self.bottomView);
        make.left.equalTo(self.bottomView.mas_centerX);
        make.height.mas_equalTo(FITSCALE(40));
    }];
    [self.accoutLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.leftButton.mas_bottom).offset(FITSCALE(40));
        make.centerX.equalTo(self.view);
    }];
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.accoutLabel.mas_bottom).offset(FITSCALE(15));
        make.centerX.equalTo(self.view);
    }];
    [self.centerButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentLabel.mas_bottom).offset(FITSCALE(19));
        make.left.equalTo(self.bottomView).offset(FITSCALE(11));
        make.right.equalTo(self.bottomView).offset(FITSCALE(-11));
        make.height.mas_equalTo(FITSCALE(46));
    }];
    [self.bottomImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.centerButton.mas_bottom).offset(FITSCALE(15));
        make.left.equalTo(self.bottomView).offset(FITSCALE(46));
    }];
    [self.bottomLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.bottomImage);
        make.left.equalTo(self.bottomImage.mas_right).offset(FITSCALE(4));
    }];
    [self.bottomButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.bottomLabel);
        make.left.equalTo(self.bottomLabel.mas_right);
    }];
}
#pragma mark - private
- (void)money{ //资金记录
    ZH_MineMoneyRecordViewController *vc = [[ZH_MineMoneyRecordViewController alloc] init];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 4;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return FITSCALE(43);
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return CGFLOAT_MIN;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return CGFLOAT_MIN;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        ZH_WalletTableViewCell *cell = [ZH_WalletTableViewCell cellWithTableView:tableView];
        cell.leftString = @"不可提现";
        return cell;
    }
    else if (indexPath.row == 1) {
        ZH_WalletTableViewCell *cell = [ZH_WalletTableViewCell cellWithTableView:tableView];
        cell.leftString = @"课程未结束";
        [cell leftLabelColor];
        return cell;
    }
    else if (indexPath.row == 2) {
        ZH_WalletTableViewCell *cell = [ZH_WalletTableViewCell cellWithTableView:tableView];
        cell.leftString = @"合计";
        return cell;
    }
    else if (indexPath.row == 3) {
        ZH_WalletTableViewCell *cell = [ZH_WalletTableViewCell cellWithTableView:tableView];
        cell.leftString = @"可提现";
        return cell;
    }
    return nil;
}
#pragma mark - button
- (void)button:(UIButton *)btn{
    if (btn.tag == 1) {//提现记录
        ZH_MineWithdrawalViewController *vc = [[ZH_MineWithdrawalViewController alloc] init];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
    }
    else if (btn.tag == 2){//我的账户
        ZH_MineAccoutViewController *vc = [[ZH_MineAccoutViewController alloc] init];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
    }
}
#pragma mark - getter,setter
- (UIView *)backView{
    if (!_backView) {
        UIView *view = [UIView createViewWithBackgroundColor:[UIColor colorWithHexString:@"#00C9AE"]];
        [self.view addSubview:_backView = view];
    }
    return _backView;
}
- (UIImageView *)bgView{
    if (!_bgView) {
        UIImageView *image = [UIImageView createImageViewWithName:@"img_zdxq"];
        [self.view addSubview:_bgView = image];
    }
    return _bgView;
}
- (UILabel *)moneyLabel{
    if (!_moneyLabel) {
        UILabel *label = [UILabel createLabelWithText:@"￥0.00" font:kFontSize_36];
        label.textColor = kFontColorWhite;
        [self.view addSubview:_moneyLabel = label];
    }
    return _moneyLabel;
}
- (UILabel *)yuLabel{
    if (!_yuLabel) {
        UILabel *label = [UILabel createLabelWithText:@"我的余额" font:kFontSize_28];
        label.textColor = kFontColorWhite;
        [self.view addSubview:_yuLabel = label];
    }
    return _yuLabel;
}
- (UITableView *)tableView{
    if (!_tableView) {
        UITableView *tableView = [UITableView createTableViewWithDelegateTarget:self];
        tableView.backgroundColor = kFontColorWhite;
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        tableView.scrollEnabled = NO;
        [self.view addSubview:_tableView = tableView];
    }
    return _tableView;
}
- (UIView *)bottomView{
    if (!_bottomView) {
        UIView *view = [UIView createViewWithBackgroundColor:kFontColorWhite];
        [self.view addSubview:_bottomView = view];
    }
    return _bottomView;
}
- (UIButton *)leftButton{
    if (!_leftButton) {
        UIButton *button = [UIButton createNoBgButtonWithTitle:@"提现" target:self action:nil];
        [button setTitleColor:kFontColorWhite forState:UIControlStateNormal];
        button.backgroundColor = [UIColor colorWithHexString:@"#00C9AE"];
        button.titleLabel.font = kFontSize_34;
        button.layer.borderWidth = FITSCALE(1);
        button.layer.borderColor = [UIColor colorWithHexString:@"#DFDFDF"].CGColor;
        [self.view addSubview:_leftButton = button];
    }
    return _leftButton;
}
- (UIButton *)rightButton{
    if (!_rightButton) {
        UIButton *button = [UIButton createNoBgButtonWithTitle:@"提现记录" target:self action:@selector(button:)];
        button.tag = 1;
        [button setTitleColor:[UIColor colorWithHexString:@"#00C9AE"] forState:UIControlStateNormal];
        button.backgroundColor = kFontColorWhite;
        button.titleLabel.font = kFontSize_34;
        button.layer.borderWidth = FITSCALE(1);
        button.layer.borderColor = [UIColor colorWithHexString:@"#DFDFDF"].CGColor;
        [self.view addSubview:_rightButton = button];
    }
    return _rightButton;
}
- (UILabel *)accoutLabel{
    if (!_accoutLabel) {
        UILabel *label = [UILabel createLabelWithText:@"我的账户" font:kFontSize_34];
        label.textColor = [UIColor colorWithHexString:@"#00C9AE"];
        [self.view addSubview:_accoutLabel = label];
    }
    return _accoutLabel;
}
- (UILabel *)contentLabel{
    if (!_contentLabel) {
        UILabel *label = [UILabel createLabelWithText:@"一个账号只可以绑定一个第三方资金账户\n绑定后不可更改" font:kFontSize_26];
        [label lableAutoLinefeed];
        label.textAlignment = NSTextAlignmentCenter;
        [self.view addSubview:_contentLabel = label];
    }
    return _contentLabel;
}
- (UIButton *)centerButton{
    if (!_centerButton) {
        UIButton *button = [UIButton createNoBgButtonWithTitle:@"管理我的账户" target:self action:@selector(button:)];
        button.tag = 2;
        [button setTitleColor:[UIColor colorWithHexString:@"#00C9AE"] forState:UIControlStateNormal];
        button.layer.cornerRadius = FITSCALE(22);
        button.layer.borderWidth = FITSCALE(1);
        button.layer.borderColor = [UIColor colorWithHexString:@"#00C9AE"].CGColor;
        [self.view addSubview:_centerButton = button];
    }
    return _centerButton;
}
- (UIImageView *)bottomImage{
    if (!_bottomImage) {
        UIImageView *image = [UIImageView createImageViewWithName:@"icon_ts"];
        [self.view addSubview:_bottomImage = image];
    }
    return _bottomImage;
}
- (UILabel *)bottomLabel{
    if (!_bottomLabel) {
        UILabel *label = [UILabel createLabelWithText:@"快速提现: 试用支付宝收款码便捷提现!" font:kFontSize_24];
        label.textColor = [UIColor colorWithHexString:@"#999999"];
        [self.view addSubview:_bottomLabel = label];
    }
    return _bottomLabel;
}
- (UIButton *)bottomButton{
    if (!_bottomButton) {
        UIButton *button = [UIButton createNoBgButtonWithTitle:@"去上传" target:self action:nil];
        [button setTitleColor:[UIColor colorWithHexString:@"#00C9AE"] forState:UIControlStateNormal];
        button.titleLabel.font = kFontSize_24;
//        button.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
        [self.view addSubview:_bottomButton = button];
    }
    return _bottomButton;
}
@end
